<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="直播间Id" prop="liveRoomId">
        <el-input
          v-model="queryParams.liveRoomId"
          placeholder="请输入直播间Id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数字1" prop="extraI1">
        <el-input
          v-model="queryParams.extraI1"
          placeholder="请输入数字1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数字2" prop="extraI2">
        <el-input
          v-model="queryParams.extraI2"
          placeholder="请输入数字2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数字3" prop="extraI3">
        <el-input
          v-model="queryParams.extraI3"
          placeholder="请输入数字3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数字4" prop="extraI4">
        <el-input
          v-model="queryParams.extraI4"
          placeholder="请输入数字4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数字5" prop="extraI5">
        <el-input
          v-model="queryParams.extraI5"
          placeholder="请输入数字5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <!-- <el-input
          v-model="queryParams.state"
          placeholder="请输入状态，pre记录，done处理"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select v-model="queryParams.state" clearable placeholder="Select" style="width: 240px">
          <el-option
            v-for="item in StatusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['front:client_err_record:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['front:client_err_record:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['front:client_err_record:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['front:client_err_record:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="client_err_recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="自增id" align="center" prop="id" />
      <el-table-column label="直播间Id" align="center" prop="liveRoomId" />
      <el-table-column label="描述" width="500px" align="center" prop="description" />
      <el-table-column label="环境" width="200px" align="center" prop="env" />
      <el-table-column label="字符串1" width="300px" align="center" prop="extraS1" />
      <el-table-column label="字符串2" width="300px" align="center" prop="extraS2" />
      <el-table-column label="字符串3" width="300px" align="center" prop="extraS3" />
      <el-table-column label="字符串4" width="300px" align="center" prop="extraS4" />
      <el-table-column label="字符串5" width="300px" align="center" prop="extraS5" />
      <el-table-column label="数字1" align="center" prop="extraI1" />
      <el-table-column label="数字2" align="center" prop="extraI2" />
      <el-table-column label="数字3" align="center" prop="extraI3" />
      <el-table-column label="数字4" align="center" prop="extraI4" />
      <el-table-column label="数字5" align="center" prop="extraI5" />
      <el-table-column label="状态" align="center" prop="state" />
      <el-table-column label="创建时间" align="center" prop="createAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据变更时间" align="center" prop="updateAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['front:client_err_record:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['front:client_err_record:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改前端错误数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="直播间Id" prop="liveRoomId">
          <el-input v-model="form.liveRoomId" placeholder="请输入直播间Id" />
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="环境" prop="env">
          <el-input v-model="form.env" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="字符串1" prop="extraS1">
          <el-input v-model="form.extraS1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="字符串2" prop="extraS2">
          <el-input v-model="form.extraS2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="字符串3" prop="extraS3">
          <el-input v-model="form.extraS3" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="字符串4" prop="extraS4">
          <el-input v-model="form.extraS4" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="字符串5" prop="extraS5">
          <el-input v-model="form.extraS5" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="数字1" prop="extraI1">
          <el-input v-model="form.extraI1" placeholder="请输入数字1" />
        </el-form-item>
        <el-form-item label="数字2" prop="extraI2">
          <el-input v-model="form.extraI2" placeholder="请输入数字2" />
        </el-form-item>
        <el-form-item label="数字3" prop="extraI3">
          <el-input v-model="form.extraI3" placeholder="请输入数字3" />
        </el-form-item>
        <el-form-item label="数字4" prop="extraI4">
          <el-input v-model="form.extraI4" placeholder="请输入数字4" />
        </el-form-item>
        <el-form-item label="数字5" prop="extraI5">
          <el-input v-model="form.extraI5" placeholder="请输入数字5" />
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <!-- <el-input v-model="form.state" placeholder="请输入状态，pre记录，done处理" /> -->
          <el-select v-model="form.state" clearable placeholder="Select" style="width: 240px">
          <el-option
            v-for="item in StatusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        </el-form-item>
        <el-form-item label="创建时间" prop="createAt">
          <el-date-picker clearable
            v-model="form.createAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数据变更时间" prop="updateAt">
          <el-date-picker clearable
            v-model="form.updateAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择数据变更时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listClient_err_record, getClient_err_record, delClient_err_record, addClient_err_record, updateClient_err_record } from "@/api/front/client_err_record"

export default {
  name: "Client_err_record",
  data() {
    return {
      StatusOptions: [
        { label: '待处理', value: 'pre' },
        { label: '已处理', value: 'done' }
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 前端错误数据表格数据
      client_err_recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        liveRoomId: null,
        env: null,
        extraS3: null,
        extraS4: null,
        extraS5: null,
        extraI1: null,
        extraI2: null,
        extraI3: null,
        extraI4: null,
        extraI5: null,
        state: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        liveRoomId: [
          { required: true, message: "直播间Id不能为空", trigger: "blur" }
        ],
        state: [
          { required: true, message: "状态，pre记录，done处理不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询前端错误数据列表 */
    getList() {
      this.loading = true
      listClient_err_record(this.queryParams).then(response => {
        this.client_err_recordList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        liveRoomId: null,
        description: null,
        env: null,
        extraS1: null,
        extraS2: null,
        extraS3: null,
        extraS4: null,
        extraS5: null,
        extraI1: null,
        extraI2: null,
        extraI3: null,
        extraI4: null,
        extraI5: null,
        state: null,
        createAt: null,
        updateAt: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加前端错误数据"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getClient_err_record(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改前端错误数据"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateClient_err_record(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addClient_err_record(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除前端错误数据编号为"' + ids + '"的数据项？').then(function() {
        return delClient_err_record(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('front/client_err_record/export', {
        ...this.queryParams
      }, `client_err_record_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
